<?php

namespace App\Admin\Extensions\Grid;

use Dcat\Admin\Grid\Displayers\AbstractDisplayer;

class AppThumb extends AbstractDisplayer
{
    public function display($width = 80, $height = 100): string
    {
        $path = $this->column->getOriginal();

        if (empty($path)) {
            return '';
        }

        if (url()->isValidUrl($path) || mb_strpos($path, 'data:image') === 0) {
            $src = $thumbSrc = $path;
        } else {
            $thumbPath = str_replace('.', '-thumb.', $path);
            $thumbSrc = $this->row->application->domainPool?->storage()->url($thumbPath);
            $src = $this->row->application->domainPool?->storage()->url($path);
        }

        return <<<HTML
            <img data-action="preview-img" src="$thumbSrc" data-src="$src" style="max-width:{$width}px;max-height:{$height}px" class="img img-thumbnail" alt="">
            HTML;
    }
}

//
//namespace Dcat\Admin\Grid\Displayers;
//
//use Illuminate\Support\Facades\Storage;
//
//class Thumb extends AbstractDisplayer
//{
//    protected string $baseClass = 'thumb';
//
//
//}
